package org.zfes.snowier.cloud.zbss.widget.act.route.service;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.web.util.WebUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.zfes.snowier.cloud.zbss.widget.act.BizConsts;
import org.zfes.snowier.cloud.zbss.widget.act.UpLoadUitl;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;

@Controller("zfes.snowier.projects.culture.router.admin.cultrueStatuteController")
@RequestMapping("/active/file")
public class FileController {

	@RequestMapping(value="/uploadImg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadProjecImg(HttpServletRequest  request, @RequestParam(name="file",required=false)MultipartFile file)  {
		ZAssert.notNull(file,"请选择文件");
		 String docPath="";
		 try {
			 docPath=UpLoadUitl.tranferFileImg(file,BizConsts.imgRootPath);
		 }catch (Exception e) {
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 Map<String, Object> msg = new HashMap<String, Object>();  
         msg.put("error", 0);  
         String ctc="/"+WebUtils.toHttp(request).getContextPath()+ docPath;
         msg.put("url",ctc);  
		 return msg;
	}
}
